home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form BinTreeForm
- Caption = "Binary Tree"
- ClientHeight = 4335
- ClientLeft = 1095
- ClientTop = 1275
- ClientWidth = 7470
- Height = 5025
- Left = 1035
- LinkTopic = "Form1"
- ScaleHeight = 289
- ScaleMode = 3 'Pixel
- ScaleWidth = 498
- Top = 645
- Width = 7590
- Begin VB.CheckBox TaperCheck
- Caption = "Taper Branches"
- Height = 255
- Left = 240
- TabIndex = 3
- Top = 1200
- Width = 1455
- End
- Begin VB.TextBox DThetaText
- Height = 285
- Left = 1320
- MaxLength = 3
- TabIndex = 2
- Text = "36"
- Top = 720
- Width = 615
- End
- Begin VB.TextBox ScaleText
- Height = 285
- Left = 1320
- MaxLength = 5
- TabIndex = 1
- Text = "0.75"
- Top = 360
- Width = 615
- End
- Begin VB.PictureBox Canvas
- AutoRedraw = -1 'True
- Height = 4335
- Left = 2040
- ScaleHeight = 285
- ScaleMode = 3 'Pixel
- ScaleWidth = 357
- TabIndex = 6
- Top = 0
- Width = 5415
- End
- Begin VB.CommandButton CmdGo
- Caption = "Go"
- Default = -1 'True
- Height = 495
- Left = 600
- TabIndex = 4
- Top = 1680
- Width = 735
- End
- Begin VB.TextBox LevelText
- Height = 285
- Left = 1320
- MaxLength = 3
- TabIndex = 0
- Text = "5"
- Top = 0
- Width = 615
- End
- Begin VB.Label Label3
- Caption = "DTHETA"
- Height = 255
- Left = 0
- TabIndex = 8
- Top = 720
- Width = 735
- End
- Begin VB.Label Label2
- Caption = "LENGTH_SCALE"
- Height = 255
- Left = 0
- TabIndex = 7
- Top = 360
- Width = 1335
- End
- Begin VB.Label Label1
- Caption = "Level"
- Height = 255
- Left = 0
- TabIndex = 5
- Top = 0
- Width = 495
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "BinTreeForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Const PI = 3.14159
- Const PI_2 = PI / 2
- Const PI_5 = PI / 5
- Dim LengthScale As Single
- Dim DTheta As Single
- Dim TheLevel As Integer
- Dim StartX As Integer
- Dim StartY As Integer
- Dim StartLength As Integer
- ' ************************************************
- ' Recursively draw a binary tree branch.
- ' ************************************************
- Sub DrawBranch(thickness As Integer, level As Integer, x As Integer, y As Integer, length As Integer, theta As Single)
- Dim x1 As Integer
- Dim y1 As Integer
- Dim status As Integer
- ' See where this branch should end.
- x1 = x + length * Cos(theta)
- y1 = y + length * Sin(theta)
- If thickness > 0 Then Canvas.DrawWidth = thickness
- Canvas.Line (x, y)-(x1, y1)
- ' If level > 1, draw the attached branches.
- If level > 1 Then
- DrawBranch thickness - 1, level - 1, x1, y1, length * LengthScale, theta + DTheta
- DrawBranch thickness - 1, level - 1, x1, y1, length * LengthScale, theta - DTheta
- End If
- End Sub
- Private Sub CmdGo_Click()
- Dim taper As Integer
- Canvas.Cls
- MousePointer = vbHourglass
- DoEvents
- If Not IsNumeric(LevelText.Text) Then _
- LevelText.Text = "5"
- TheLevel = CInt(LevelText.Text)
- If Not IsNumeric(ScaleText.Text) Then _
- ScaleText.Text = "0.75"
- LengthScale = CSng(ScaleText.Text)
- If Not IsNumeric(DThetaText.Text) Then _
- DThetaText.Text = "36"
- DTheta = CSng(DThetaText.Text) * PI / 180#
- If TaperCheck.Value = vbChecked Then
- taper = TheLevel
- Else
- taper = 0
- End If
- StartLength = (Canvas.ScaleHeight - 10) / _
- ((1 - LengthScale ^ (TheLevel + 1)) / (1 - LengthScale))
- DrawBranch taper, TheLevel, StartX, StartY, StartLength, -PI_2
- MousePointer = vbDefault
- End Sub
- Private Sub Form_Load()
- TheLevel = CInt(LevelText.Text)
- End Sub
- Private Sub Form_Resize()
- Canvas.Move Canvas.Left, 0, _
- ScaleWidth - Canvas.Left, ScaleHeight
- StartX = Canvas.ScaleWidth \ 2
- StartY = Canvas.ScaleHeight - 5
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-